package com.apes.sms.masterdata.repository;


import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.sms.masterdata.model.SupplierProduct;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Created by lishikun on 2021/12/23 16:16
 */
public interface SupplierProductRepository extends CustomRepository<SupplierProduct, String> {

    @Query(value="select T from SupplierProduct T where T.supplier.id = :supplierId and T.uuid in :uuids")
    List<SupplierProduct> findAllByUuidAndSupplierId(List uuids, String supplierId);
    SupplierProduct findFirstByUuidAndSupplierId(String uuid, String SupplierId);

    @Modifying
    @Transactional
    @Query(
            value = "UPDATE sms_supplier_product  SET STATE = 'onShelf' WHERE STATE ='toBeShelf' AND SUPPLIER_ID = ?1 ",
            nativeQuery = true
    )
    int onShelfAllBySupplierId(String SupplierId);
    @Query(value="select T from SupplierProduct T where  T.state =:state and T.supplier.id = :supplierId  ")
    Page<SupplierProduct> findAllBySupplierAndState(@Param("supplierId")String supplierId, @Param("supplierId")String state, Pageable pageable);
}
